

class Queue:


    def __init__(self,logic_size):
        self.actual_size=logic_size+1
        self.queue=[None for _ in range(self.actual_size)]
        self.front=0
        self.rear=0

    def is_empty(self):
        return self.front==self.rear

    def is_full(self):
        return (self.rear+1)%self.actual_size==self.front

    def enqueue(self,ele):
        if self.is_full():
            raise Exception('队列已满')
        else:
            self.rear=self.rear+1
            if self.rear==self.actual_size:
                self.rear=0
            self.queue[self.rear]=ele

    def dequeue(self):
        if self.is_empty():
            raise Exception('队列为空')
        else:
            self.front=self.front+1
            if self.front==self.actual_size:
                self.front=0
            self.queue[self.front] = None

    def get_head(self):
        if self.is_empty():
            raise Exception('队列为空')
        else:
            return self.queue[(self.front+1)%self.actual_size]

    def get_tail(self):
        if self.is_empty():
            raise Exception('队列为空')
        else:
            return self.queue[self.rear]


if __name__ == '__main__':
    queue=Queue(4)
    queue.enqueue(1)
    print(queue.queue,queue.get_head(),queue.get_tail())
    queue.enqueue(2)
    queue.enqueue(3)
    print(queue.queue, queue.get_head(), queue.get_tail())
    queue.enqueue(4)
    try:
        queue.enqueue(5)
    except Exception as e:
        print(e)
    print(queue.queue, queue.get_head(), queue.get_tail())

    queue.dequeue()
    queue.dequeue()
    queue.dequeue()

    print(queue.queue, queue.get_head(), queue.get_tail())

    queue.enqueue(6)

    print(queue.queue, queue.get_head(), queue.get_tail())

    queue.dequeue()
    queue.dequeue()

    try:
        print(queue.queue, queue.get_head(), queue.get_tail())
    except Exception as e:
        print(e)
